package com.hst.capacity.facade.rest;


import cn.hutool.core.map.MapUtil;
import com.hst.capacity.application.biz.NotificationBiz;
import com.hst.capacity.application.biz.TokenBiz;
import com.hst.capacity.domain.model.entity.auth.TokenEntity;
import com.hst.capacity.domain.model.request.notification.NotificationParam;
import com.hst.capacity.domain.model.request.notification.SmsContextParam;
import com.hst.capacity.domain.model.response.DefaultVO;
import com.hst.capacity.infra.util.StringUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


import javax.servlet.http.HttpServletRequest;

import static com.hst.capacity.domain.model.response.DefaultVO.success;

/**
 *  订单共通接口
 *
 * */
@RequestMapping("/notification")
@RestController
public class NotificationController {

    @Autowired
    NotificationBiz notificationBiz;

    @Autowired
    TokenBiz tokenBiz;

    /**
     * 新订单提醒
     * @param param
     * @return
     */
    @PostMapping("/new-order/remind")
    private DefaultVO newOrderRemind(@RequestBody NotificationParam param, HttpServletRequest request){
        param.setIdDispatcher(tokenBiz.findIdUser(request));
        return success(notificationBiz.newOrderRemind(param));
    }

    /**
     * 读取新订单消息
     * @param param
     * @return
     */
    @PostMapping("/new-order/message/read")
    private DefaultVO newOrderMessageRead(@RequestBody NotificationParam param, HttpServletRequest request){
        String idDispatcher = tokenBiz.findIdUser(request);
        notificationBiz.clearNewOrderRemind(idDispatcher, param.getIdFranchisee());
        return success(MapUtil.builder("success","新单消息已读").build());
    }

    /**
     * 发短信消息
     * @param param
     * @return
     */
    @PostMapping("/sms/message")
    private DefaultVO sendSmsMessage(@RequestBody SmsContextParam param){
        notificationBiz.sendSmsMessage(param.getMobile(), param.getContext());
        return success(MapUtil.builder("success","短信发送成功").build());
    }

}
